package com.team.RunsFast_Api.controller;

import com.team.RunsFast_Api.config.SystemConfig;
import com.team.RunsFast_Api.dto.OrderAddDto;
import com.team.RunsFast_Api.dto.OrderPreDto;
import com.team.RunsFast_Api.dto.UpdateOrderDto;
import com.team.RunsFast_Api.service.intf.OrderService;
import com.team.runsfast.entity.Order;
import com.team.runsfast.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/order/")
@CrossOrigin
@Api(tags = "订单相关操作")
public class OrderController {
    @Autowired
    private OrderService service;

    /**新增*/
    @PostMapping("save.do")
    public R save(Order obj){
        return service.save(obj);
    }

    /**查询*/
    @GetMapping("all.do")
    public R all(){
        return service.queryAll();
    }

    @PostMapping("preview.do")
    public R preview(@RequestBody OrderPreDto dto, HttpServletRequest request){
        return service.queryPre(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @PostMapping("create.do")
    public R create(@RequestBody OrderAddDto dto, HttpServletRequest request){
        return service.createOrder(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @PostMapping("updatestate.do")
    public R preview(@RequestBody UpdateOrderDto orderDto){
        return service.updateNo(orderDto.getFlag(),orderDto.getNo());
    }

    @GetMapping("orderquery.do")
    public R OrderQuery(HttpServletRequest request){
        return service.queryAll(request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @GetMapping("ordernum.do")
    public R OrderNum(HttpServletRequest request){
        return service.queryNum(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}